class RangeIterator {
    constructor(start, stop) {
        this.start = start
        this.stop = stop
        this.value = start
    }

    [Symbol.iterator]() {
        return {
            next: () => {

                if (this.value < this.stop) {
                    let res = {
                        done: false,
                        value: this.value
                    }
                    this.value += 1
                    return res
                } else {
                    return {
                        done: true,
                        value: undefined
                    }
                }

            }
        }
    }
}

function range(start, stop) {
    return new RangeIterator(start, stop);
}

// 这里只能有 obj 才能用 for...of 结构
for (let value of range(0, 3)) {
    console.log(value);
}
